<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>权限管理</title>
<script type="text/javascript">
<!--
	function checkMe(obj){
		var id =obj.id;
		if (obj.checked)
		{
			$("."+id).prop("checked",true);
		}else{
			$("."+id).prop("checked",false);
		}
	}
//-->
</script>
</head>
<body>
	<!-- 标题 -->
	<div class="titleBar m_b_20">
		<div class="tit fl b_l_e74a5f">
			<h3 class="cn">新增权限</h3>
			<span class="en">authority information</span>
		</div>
		<div class="fr"></div>
	</div>
	<!-- end 标题 -->
	<form action="#" id="editFm" method="post" ><input type="hidden" name="id" id="dealid" value="${dto.id}">
		<div class="m_b_20">
			<span class="formspan"> 
				<label>名称</label> 
				<input type="text" name="name" id="name" style="width:150px;" class="input_style2" value="${dto.name}">
			</span>
		</div>
		<div class="m_b_20">
			<h5>权限设置</h5> 
		</div>

		<div class="m_b_20">
				<table class="tb_style02" width="100%">
					<c:forEach items="${rows}" var="row">
						<c:choose>
							<c:when test="${row.odd}">
								<tr>
							</c:when>
							<c:otherwise>
								<td width="2%"></td>
							</c:otherwise>
						</c:choose>
						<td>
							<table cellpadding="0" cellspacing="0" border="0">
								<c:forEach items="${row.menus}" var="menu">
									<c:choose>
										<c:when test="${menu.index==1}">
											<tr>
												<td rowspan="${row.menuSize}">
													<h6 class="checkvalue">
														<input type="checkbox" onclick="checkMe(this);" id="pack_${row.pack.id}" value="${row.pack.id}"/>
														${row.pack.name}
													</h6>
												</td>
												<td>
													<span class="checkvalue">
														<input type="checkbox" onclick="checkMe(this);" value="${menu.id}" class="pack_${row.pack.id}" id="menu_${menu.id}"/>${menu.menuName}
													</span>
												</td>
												<c:forEach items="${menu.operates}" var="op">
													<td width="11%">
														<c:if test="${op.resourceId gt 0}">
															<span class="checkvalue">
																<input type="checkbox" name="resourceIds" value="${op.resourceId}" class="pack_${row.pack.id} menu_${menu.id}" ${op.checked?'checked':''}> ${op.operateName}
															</span>
														</c:if>
													</td>
												</c:forEach>
											</tr>
										</c:when>
										<c:otherwise>
											<tr>
												<td>
													<span class="checkvalue">
														<input type="checkbox" onclick="checkMe(this);" value="${menu.id}" class="pack_${row.pack.id}" id="menu_${menu.id}">${menu.menuName}
													</span>
												</td>
												<c:forEach items="${menu.operates}" var="op">
													<td>
														<c:if test="${op.resourceId gt 0}">
															<span class="checkvalue">
																<input type="checkbox" name="resourceIds" value="${op.resourceId}" class="pack_${row.pack.id} menu_${menu.id}" ${op.checked?'checked':''}> ${op.operateName}
															</span>
														</c:if>
													</td>
												</c:forEach>
											</tr>
										</c:otherwise>
									</c:choose>
								</c:forEach>
							</table>
						</td>
					</c:forEach>
					<c:choose>
						<c:when test="${row.odd}">
							<c:if test="${row.last}">
								</tr>
							</c:if>
						</c:when>
						<c:otherwise>
							</tr>
						</c:otherwise>
					</c:choose>
				</table>
		</div>

		<div class="m_b_20"> 
			<label>描述 </label>
			<textarea style="width: 90%; height: 100px;"
				class="textarea_style1" name="description" id="description">${dto.description}</textarea>	
		</div>
		<div class="m_b_20">
			<input style="width: 110px;" class="btn_brown02 m_r_12" type="button" name="saveButton" id="saveButton" value="确  定"> 
			<input style="width: 110px;" class="btn_brown02 m_r_12" type="button" name="cancelButton" id="cancelButton" value="取  消">
		</div>
	</form>		
<script type="text/javascript">
<!--
		$("#cancelButton").click(function(){
			window.location.href="${pageContext.request.contextPath}/backend/system/authority/search";
		});
		$("#saveButton").click(function(){
			var bValid = doValid();
			if(bValid){
				$.ajax({
				url:"${pageContext.request.contextPath}/backend/system/authority/savePage",
				type: 'POST',
				data: $("#editFm").serialize(),
					
				error: function(XMLHttpRequest, textStatus, errorThrown){alert('保存异常。' + textStatus + "/" + errorThrown);},
				success: function(data){
					if(data.result==1) {
						// var isAdd = false;
						var isAdd = $("#dealid").val() == null || $("#dealid").val() == "0";
						if (isAdd) {
							//alert('添加成功.');
							$.dialog.alert({title:"保存",content:"添加成功"});
						}
						else {
							//alert('添加/修改成功.');
							$.dialog.alert({title:"保存",content:"添加/修改成功"});
						}
						//query();
						//window.location.reload();
						window.location.href="${pageContext.request.contextPath}/backend/system/authority/search";
					} else {
						//alert("保存失败："+data.errorMessage);
						if (data.errorMessage)
						{
							//alert("保存失败："+data.errorMessage);
							$.dialog.alert({title:"保存",content:"保存失败："+data.errorMessage});
						}else{
							if (data.indexOf("您的输入含有非法字符")>=0)
							{
								//alert("您的输入含有非法字符");
								$.dialog.alert({title:"保存",content:"您的输入含有非法字符"});
							}else
								//alert("保存失败："+data);
								$.dialog.alert({title:"保存",content:"保存失败："+data});
						}
					}
				}
			});
			}
		});
		
		function doValid() {
			var name = $("#name").val();
			if (isNull(name))
			{
				$.dialog.alert({title:"保存",content:"名称不能为空！",objCtrl:"#name"});
				obj.trigger("focus");
				return false;
			}
			return true;
		}
		
//-->
</script>
</body>
</html>